package com.yuan.service.impl;

import com.yuan.bean.SysUser;
import com.yuan.service.AsyncService;
import com.yuan.service.SysUserService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * @Author：YuanHaHa
 * @Date：2024/7/4 16:44
 */
@Service
public class AsyncServiceImpl implements AsyncService {

    @Async("threadPoolTaskExecutor")
    @Override
    public void executorAsync(List<SysUser> list, SysUserService sysUserService, CountDownLatch countDownLatch) {
        try {
            // 有可能会有异常
            sysUserService.saveBatch(list);
        } finally {
            countDownLatch.countDown();
        }
    }
}
